Skip to content

perf(runtime-config): cache env names of runtime config keys - #35

Merged
pi0 merged 2 commits into
nitrojs:mainfrom
brunobelloni:perf/env-key-cache
Nov 12, 2026
Merged

pi0 merged 2 commits into
nitrojs:mainfrom
brunobelloni:perf/env-key-cache

Conversation

@brunobelloni

Copy link
Copy Markdown
Contributor

🔗 Linked issue

None. Nitro v3 already keeps the resolved runtime config in useRuntimeConfig (_cached), so this only applies to v2, which Nuxt 4 uses.

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

useRuntimeConfig(event) runs applyEnv over the whole runtime config on every request. In Nuxt that means the SSR render plus every internal $fetch. For each key, getEnv converts the key path to its env name with snakeCase(key).toUpperCase(). That name only depends on the key, but it is recomputed every time.

When I profiled SSR of a Nuxt 4 page on Cloudflare Workers, snakeCase was ~75% of the time spent in applyEnv. This PR caches the env name per key, capped at 5,000 entries in case keys are not bounded. Env values are still read from process.env on every call, and the added test covers that.

applyEnv on a runtime config with ~250 nested camelCase keys (Node 26, 3,000 runs after warm-up):

per applyEnv
before ~1.02 ms
after ~0.42 ms

We have run the same change as a pnpm patch in production since October.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 10, 2026

Copy link
Copy Markdown

@ops4000 is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aeb7658a-cbea-4925-b64d-89f04f251d8f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@pi0
pi0 merged commit a6da50e into nitrojs:main Nov 12, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants